#include "../../mqserver/binding.hpp"
#include <gtest/gtest.h>

MyRabbitMQ::BindingManager::ptr bindings;

class BindingTest : public testing::Environment
{
public:
    // 初始化
    virtual void SetUp() override
    {
        bindings = std::make_shared<MyRabbitMQ::BindingManager>("./data.db");
    }

    virtual void TearDown() override
    {
        // 清理队列操作
        // msgQueues->clear();
        std::cout << "执行真正数据库清理操作" << std::endl;
    }
};
    //// 声明测试
    //TEST(BindingTest, insert_test)
    //{
    //    bindings->declareBinding("exchange-1","queue-1","news.music",true);
    //    bindings->declareBinding("exchange-2","queue-2","news.music",true);
    //    bindings->declareBinding("exchange-3","queue-3","news.music",true);
    //    bindings->declareBinding("exchange-4","queue-4","news.music",true);
    //    bindings->declareBinding("exchange-5","queue-5","news.music",false);
    //    bindings->declareBinding("exchange-6","queue-6","news.music",false);
    //    bindings->declareBinding("exchange-7","queue-7","news.music",true);
    //    bindings->declareBinding("exchange-8","queue-8","news.music",true);

    //    bindings->declareBinding("exchange-1","queue-8","news.music",true);
    //    bindings->declareBinding("exchange-2","queue-8","news.music",true);
    //    bindings->declareBinding("exchange-3","queue-8","news.music",true);
    //    bindings->declareBinding("exchange-4","queue-8","news.music",true);
    //    bindings->declareBinding("exchange-5","queue-8","news.music",true);
    
    //    bindings->declareBinding("exchange-2","queue-1","news.music",true);
    //    bindings->declareBinding("exchange-3","queue-1","news.music",true);
    //    bindings->declareBinding("exchange-4","queue-1","news.music",true);
    //    bindings->declareBinding("exchange-5","queue-1","news.music",true);
    //}

    //// 删除测试
    //TEST(BindingTest, delete_test)
    //{
    //   bindings->deleteBinding("exchange-1","queue-1");
    //   bindings->deleteBinding("exchange-2","queue-2");

    //   bindings->deleteExchangeBindings("exchange-3");
    //   bindings->deleteMsgQueueBindings("queue-8");
    //}

    // 获取指定与获取全部测试
    TEST(BindingTest, get_test)
    {
        auto test1 = bindings->getBinding("exchange-2","queue-4");                        
        auto test2 = bindings->getBinding("exchange-2","queue-1");                        
        auto test3 = bindings->getBinding("exchange-7","queue-7");            
    
        std::cout << test2->m_msgQueueName << std::endl;
        std::cout << test3->m_exchangeName << std::endl;

        auto test4 = bindings->getExchangeBindings("exchange-4");
        for(auto& f : test4)
        {
            std::cout << f.second->m_exchangeName << std::endl;
            std::cout << f.second->m_msgQueueName << std::endl;
        }
    
    }

    //判断是否存在测试
    TEST(BindingTest,exists_test)
    {
        LOG(logLevel::DEBUG) << bindings->exists("exchange-5","queue-3") << std::endl;
        LOG(logLevel::DEBUG) << bindings->exists("exchange-4","queue-1") << std::endl;
        LOG(logLevel::DEBUG) << bindings->exists("exchange-2","queue-1") << std::endl;
    }

    //获取管理数量测试
    TEST(BindingTest,getSize_test)
    {
        LOG(logLevel::DEBUG) << bindings->size() << std::endl;
    }

// //持久化恢复历史数据测试

int main(int argc, char *argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new BindingTest);
    int ret = RUN_ALL_TESTS();
    return 0;
}